﻿using System.Runtime.InteropServices;
using System;

namespace BgWorks.Common
{
    public class TimeZoneHelper
    {
        private static TimeZoneHelper instance = null;
        public static TimeZoneHelper Instance() 
        {
            if (instance == null)
                instance = new TimeZoneHelper();
             return instance;
        }
        public TimeZoneInfo GetTimeZone() 
        {

            TimeZoneInfo zone = null;
            try
            {
                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    zone = TimeZoneInfo.FindSystemTimeZoneById("China Standard Time");
                }
                else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
                {
                    zone = TimeZoneInfo.FindSystemTimeZoneById("Asia/Shanghai");
                }
            }
            catch (Exception)
            {
                LogHelper.GetLog().Error("设置时区报错！");
            }
            return zone;
        }
    }
}
